package com.shun.common.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ServletUtils常用工具类
 * @author clever
 * @since 2021-09-27
 */
public class ServletUtils {

	/**
	 * 获得servlet请求资源
	 * @return
	 */
	public static ServletRequestAttributes getRequestAttributes() {
		RequestAttributes attreibutes = RequestContextHolder.getRequestAttributes();
		return (ServletRequestAttributes) attreibutes;
	}
	
	/**
	 * 获得请求对象
	 * @return
	 */
	public static HttpServletRequest getRequest() {
		return getRequestAttributes().getRequest();
	}
	
	/**
	 * 获得应答对象
	 * @return
	 */
	public static HttpServletResponse getResponse() {
		return getRequestAttributes().getResponse();
	}
}